<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/taglib.jsp"%>
<jsp:include page="/WEB-INF/common/head.jsp" flush="true" />
<div class="easyui-panel addPage" data-options="fit:true,border:false,novalidate:true">
    <form class="easyui-form" id="ff" method="post" data-options="novalidate:true">
        <table class="table1">
            <tr>
           		<th><span>用户初始化配置:</span></th>
               	<td>
               		<div class="wrap_input">
               			<a href="#" class="easyui-linkbutton" id = "userEnter" ">确定</a>       
               			<a href="#" class="easyui-linkbutton" id = "userExport" ">用户数据导出</a>       
               		</div>
               		
           		</td>
           	</tr>
            <tr>
           		<th><span>链接初始化配置:</span></th>
               	<td>
               		<div class="wrap_input">
               			<a href="#" class="easyui-linkbutton"  id = "objEnter" >确定</a>       
               			<a href="#" class="easyui-linkbutton" id = "linkExport" >链接数据导出</a>       
               		</div>
           		</td>
           	</tr>
           	 <tr>
           		<th><span>AD登录配置:</span></th>
               	<td>
               		<div class="wrap_input">
               			<a href="#" class="easyui-linkbutton"  id = "adConfig" >AD登录配置</a>       
               		</div>
           		</td>
           	</tr>
           	 <tr>
           		<th><span>数据源配置:</span></th>
               	<td>
               		<div class="wrap_input">
               			<a href="#" class="easyui-linkbutton"  id = "sourceConfig" >数据源配置</a>       
               		</div>
           		</td>
           	</tr>
            <tr>
           		<th><span>站点同步:</span></th>
               	<td>
               		<div class="wrap_input">
               			<a href="#" class="easyui-linkbutton"  id = "siteConfig" >站点同步配置</a>       
               		</div>
           		</td>
           	</tr>
            <tr>
           		<th><span>链接配置:</span></th>
               	<td>
               		<div class="wrap_input"><input class="easyui-textbox"  style="width:20%" type="text" id= "link" name="link" value="${host}" ></input></div>
           		</td>
           	</tr>
           	<tr>
           	 	 <th></th>
               		<td>
               		<div class="wrap_input">	
               		<a href="#" class="easyui-linkbutton" id ="saveConfig"">保存</a>               		
               		</div>
           		</td>
           	</tr>
           	
        </table>
    </form>
</div>

	<script type="text/javascript">
		
	top.window.subPage.save = save;
	function save() {
		if($("#ff").form('enableValidation').form('validate')) {
			$.post("${context_path}/sys/obj/save", getParam(), function(data) {
				if (data.code == 0) {
					showMsg("配置成功");
				}  else{
					layer.alert(data.msg);
				} 
			},"json");
		}
	}
	function getParam() {
		var param = {
	       	    "name": $(":input[name='name']").val(), 
	       	    "link": $(":input[name='link']").val(), 
	       	    "type": $(":input[name='type']").val()
		}
		for(key in param) {
			if(!param[key]) {
				delete param[key];
			}
		}
		return param;
	}
	
	 $(document).ready(function () {
     });
     //用户初始化
     $("#userEnter").click(function(){
     	 var form = new FormData();
     	 form.append("file",$("#userConfig")[0].files[0])
      	  $.ajax({
      	                url:"${context_path}/sys/config/userConfig",
      	                type:"post",
      	                data:form,
      	                processData:false,
      	                contentType:false,
      	                success:function(data){
      	           		if(data.code==0){
      	           		showMsg('用户初始化成功');
	        				}else{
	        			showMsg('初始化失败，请检查文件格式是否正确');
	        				}
      	                }
      	});
     });
     //对象初始化
     $("#objEnter").click(function(){
     	 var form = new FormData();
     	 form.append("file",$("#objConfig")[0].files[0])
      	  $.ajax({
      	                url:"${context_path}/sys/config/objConfig",
      	                type:"post",
      	                data:form,
      	                processData:false,
      	                contentType:false,
      	                success:function(data){
      	                	if(data.code==0){
      	      	           		showMsg('用户初始化成功');
      		        				}else{
      		        			showMsg('初始化失败，请检查文件格式是否正确');
      		        				}
      	                }
      	});
    });
     //保存配置
     $("#saveConfig").click(function(){
     	var host = $("#link").val();
     	var submitData = {
					"host" : host
			};
     	$.post("${context_path}/sys/config/saveConfig", submitData,function(data) {
     		if(data.code==0){
	           		showMsg('保存成功');
      				}else{
      			showMsg('初始化失败，请检查文件格式是否正确');
      				} 
			},"json");
    });
     
     //导出用户
     $("#userExport").click(function(){
     	window.location.href = "${context_path}/sys/config/userExport";
     });
   //导出link
     $("#linkExport").click(function(){
     	window.location.href = "${context_path}/sys/config/linkExport";
     });
	 //站点配置
     $("#siteConfig").click(function(){
    		top.window.subPage.loadCurrDatagrid = function() {
    			showMsg("配置成功！");
    		}
    		top.openWindow("对象管理-增加", '${context_path}/sys/config/siteConfigView', {size: '600x400'});
     });
	 //站点配置
     $("#siteConfig").click(function(){
    		top.window.subPage.loadCurrDatagrid = function() {
    			showMsg("配置成功！");
    		}
    		top.openWindow("配置管理-站点配置", '${context_path}/sys/config/siteConfigView', {size: '600x400'});
     });
	 //AD配置
     $("#adConfig").click(function(){
    		top.window.subPage.loadCurrDatagrid = function() {
    			showMsg("配置成功！");
    		}
    		top.openWindow("配置管理-AD配置", '${context_path}/sys/config/loginAd', {size: '600x400'});
     });
	 //数据源配置
     $("#sourceConfig").click(function(){
    		top.window.subPage.loadCurrDatagrid = function() {
    			showMsg("配置成功！");
    		}
    		top.openWindow("配置管理-数据源配置", '${context_path}/sys/config/datasource', {size: '600x400'});
     });
	
	
		</script>
  <jsp:include page="/WEB-INF/common/dialogWindow.jsp" flush="true" />
   <jsp:include page="/WEB-INF/common/foot.jsp" flush="true" />
